package J20241102_sort;

import java.awt.*;
import java.sql.Time;
import java.util.Arrays;
import java.util.Random;
import java.util.Timer;

/**
 * Created with IntelliJ IDEA.
 * Description: 排序
 * User: 王圆豪
 * Date: 2024-11-02
 * Time: 21:55
 */
public class Test_Sort {
    public static void main(String[] args) {
        testRandom();
    }

    public static void test_quick(int[] arr){
        System.out.println("==========快速排序=========");
        int[] array = Arrays.copyOf(arr, arr.length);
        System.out.println("排序前：" + Arrays.toString(array));
        long startTime = System.nanoTime();
        Sort.quick_sort(array);
        long endTime = System.nanoTime();
        System.out.println("排序后：" + Arrays.toString(array));
        System.out.println("排序时间：" + (endTime - startTime));
    }

    public static void test_bubble(int[] arr){
        System.out.println("==========冒泡排序=========");
        int[] array = Arrays.copyOf(arr, arr.length);
        System.out.println("排序前：" + Arrays.toString(array));
        long startTime = System.nanoTime();
        Sort.bubble_sort(array);
        long endTime = System.nanoTime();
        System.out.println("排序后：" + Arrays.toString(array));
        System.out.println("排序时间：" + (endTime - startTime));
    }

    public static void test_heap(int[] arr){
        System.out.println("==========堆排序=========");
        int[] array = Arrays.copyOf(arr, arr.length);
        System.out.println("排序前：" + Arrays.toString(array));
        long startTime = System.nanoTime();
        Sort.heap_sort(array);
        long endTime = System.nanoTime();
        System.out.println("排序后：" + Arrays.toString(array));
        System.out.println("排序时间：" + (endTime - startTime));
    }

    public static void test_select(int[] arr){
        System.out.println("==========选择排序=========");
        int[] array = Arrays.copyOf(arr, arr.length);
        System.out.println("排序前：" + Arrays.toString(array));
        long startTime = System.nanoTime();
        Sort.select_sort(array);
        long endTime = System.nanoTime();
        System.out.println("排序后：" + Arrays.toString(array));
        System.out.println("排序时间：" + (endTime - startTime));
    }

    public static void test_d_insert(int[] arr){
        System.out.println("==========直接插入排序=========");
        int[] array = Arrays.copyOf(arr, arr.length);
        System.out.println("排序前：" + Arrays.toString(array));
        long startTime = System.nanoTime();
        Sort.d_insert_sort(array);
        long endTime = System.nanoTime();
        System.out.println("排序后：" + Arrays.toString(array));
        System.out.println("排序时间：" + (endTime - startTime));
    }

    public static void test_shell(int[] arr){
        System.out.println("==========希尔排序=========");
        int[] array = Arrays.copyOf(arr, arr.length);
        System.out.println("排序前：" + Arrays.toString(array));
        long startTime = System.nanoTime();
        Sort.shell_sort(array);
        long endTime = System.nanoTime();
        System.out.println("排序后：" + Arrays.toString(array));
        System.out.println("排序时间：" + (endTime - startTime));
    }
    public static void testSimple() {
        int[] arr = new int[]{8,6,4,1,3,11,6,5,2};
        test_d_insert(arr);
        test_shell(arr);
        test_select(arr);
        test_heap(arr);
        test_bubble(arr);
        test_quick(arr);
    }

    public static void testRandom(){
        Random random = new Random();
        int[] arr = new int[9];
        for (int i = 0; i < 9; i++) {
            arr[i] = random.nextInt(100);
        }
        test_d_insert(arr);
        test_shell(arr);
        test_select(arr);
        test_heap(arr);
        test_bubble(arr);
        test_quick(arr);
    }
}
